1. Technical Field
The present invention relates generally to compilers and translators for digital computer systems, and more specifically to pre-compilers for translating portions of a program source file prior to its compilation into executable code.
2. Background Art
Whenever possible, computer programmers should avoid writing new computer code to solve problems which have already been solved. Therefore, it is common for programmers to utilize previously written subprograms and utilities in order to accomplish various portions of their current programming task. Judicious use of subprogram libraries allow a programmer to create a correct, working program in much less time than required for one containing all new code.
In some fields, large systems have been created which are available for use by the programmer. This is true, for example, in the area of database systems. Instead of writing a large number of file access procedures, a programmer needing to utilize database functions in his program can invoke a library of available database management procedures. These procedures typically handle all of the details of accessing and updating database files. It is only necessary for the programmer to invoke library routines through high level subprogram calls, thus allowing the programmer to concentrate on the remaining parts of his task.
Database management systems are generally invoked using sequences of commands which are not valid programming statements in the language being used for development. For example, several well known database management systems accept commands in a formalized notation known as Structured Query Language (SQL). SQL is a command interface designed specifically for database processing functions. SQL commands are substantially different in format from programming statements used in languages such as C and COBOL.
In order to allow a programmer to include SQL commands in his application program, which is written in a language such as C, it is necessary to scan the program source code of the C program and translate all SQL commands into a format which can be understood by a C compiler. This is generally done using a pre-compiler, which accepts as input a program source file including both C code and SQL statements, and which generates an equivalent modified source file which contains only C source code. This modified source file can then be compiled by a C compiler to produce executable code.
The pre-compiler is required to understand SQL statements, and to be able to translate them to equivalent source code statements in the host programming language. Each programming language which includes embedded SQL statements must use a different pre-compiler; for example, separate pre-compilers must be written for each of the languages FORTRAN, C, Pascal, COBOL and Ada. Since the syntax and even the semantics of these and other languages are different, an appropriate pre-compiler for each language must be written nearly from scratch.
The effort and expense necessary to create a pre-compiler is quite large. This is because it is necessary for the pre-compiler to understand SQL statements as well as those of the host language. If any low level features of SQL are ever changed, it is necessary to rewrite portions of every pre-compiler.
It would therefore be desirable to provide a mechanism which would simplify the writing of pre-compilers, and simplify the maintenance thereof if changes are made to the underlying program.